package com.open.capacity.common.util.skf;

import com.sun.jna.Structure;

import java.io.ByteArrayOutputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Struct_CONTAINER extends Structure {
    public byte[] container = new byte[128];

    public static class ByReference extends Struct_CONTAINER implements Structure.ByReference {
    }

    public static class ByValue extends Struct_CONTAINER implements Structure.ByValue {
    }

    public byte[] get_container() {
        return container;
    }

    public List<String> get_containers() {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        List<String> ls = new ArrayList<String>();
        int j = 0;
        for (int i = 0; i < container.length; i++) {
            baos.write(container[i]);
            if (container[i] == 0) {
                //System.out.println(i + " cont[i] = 00" + container[i]);
                String temp = new String(baos.toByteArray()).trim();
                if (temp.length() > 0) {
                    ls.add(temp);
                    //System.out.println(j + " temp = " + temp);
                    j = j + 1;
                    baos.reset();
                }
                //break;
            }
        }
        return ls;
    }

    @Override
    protected List getFieldOrder() {
        return Arrays.asList(new String[]{"container"});
    }
}
